package com.yinhe.system.service.impl;

import java.util.List;

import com.yinhe.common.annotation.DataScope;
import com.yinhe.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yinhe.system.mapper.YhRelationshipTransferMapper;
import com.yinhe.system.domain.YhRelationshipTransfer;
import com.yinhe.system.service.IYhRelationshipTransferService;

/**
 * 关系转接Service业务层处理
 *
 * @author yinhe
 * @date 2022-09-24
 */
@Service
public class YhRelationshipTransferServiceImpl implements IYhRelationshipTransferService
{
    @Autowired
    private YhRelationshipTransferMapper yhRelationshipTransferMapper;

    /**
     * 查询关系转接
     *
     * @param id 关系转接主键
     * @return 关系转接
     */
    @Override
    public YhRelationshipTransfer selectYhRelationshipTransferById(Long id)
    {
        return yhRelationshipTransferMapper.selectYhRelationshipTransferById(id);
    }

    /**
     * 查询关系转接列表
     *
     * @param yhRelationshipTransfer 关系转接
     * @return 关系转接
     */
    @Override
    @DataScope(deptAlias = "r", userAlias = "r")
    public List<YhRelationshipTransfer> selectYhRelationshipTransferList(YhRelationshipTransfer yhRelationshipTransfer)
    {
        return yhRelationshipTransferMapper.selectYhRelationshipTransferList(yhRelationshipTransfer);
    }

    /**
     * 新增关系转接
     *
     * @param yhRelationshipTransfer 关系转接
     * @return 结果
     */
    @Override
    public int insertYhRelationshipTransfer(YhRelationshipTransfer yhRelationshipTransfer)
    {
        yhRelationshipTransfer.setCreateTime(DateUtils.getNowDate());
        return yhRelationshipTransferMapper.insertYhRelationshipTransfer(yhRelationshipTransfer);
    }

    /**
     * 修改关系转接
     *
     * @param yhRelationshipTransfer 关系转接
     * @return 结果
     */
    @Override
    public int updateYhRelationshipTransfer(YhRelationshipTransfer yhRelationshipTransfer)
    {
        yhRelationshipTransfer.setUpdateTime(DateUtils.getNowDate());
        return yhRelationshipTransferMapper.updateYhRelationshipTransfer(yhRelationshipTransfer);
    }

    /**
     * 批量删除关系转接
     *
     * @param ids 需要删除的关系转接主键
     * @return 结果
     */
    @Override
    public int deleteYhRelationshipTransferByIds(Long[] ids)
    {
        return yhRelationshipTransferMapper.deleteYhRelationshipTransferByIds(ids);
    }

    /**
     * 删除关系转接信息
     *
     * @param id 关系转接主键
     * @return 结果
     */
    @Override
    public int deleteYhRelationshipTransferById(Long id)
    {
        return yhRelationshipTransferMapper.deleteYhRelationshipTransferById(id);
    }

    /**
     * 导入用户数据
     *
     * @param relationshipTransferList      用户数据列表
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @return 结果
     */

    @Override
    public String importRelationshipTransfer(List<YhRelationshipTransfer> relationshipTransferList, Boolean isUpdateSupport)
    {
        int successNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (YhRelationshipTransfer yhRelationshipTransfer : relationshipTransferList) {
            this.insertYhRelationshipTransfer(yhRelationshipTransfer);
            successNum++;
            successMsg.append("<br/>" + successNum  + " 导入成功");
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
}

